package com.xinli.xinlifm.view.activity.player;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.xinli.xinlifm.R;
import com.xinli.xinlifm.http.bean.player.MoreBean;
import com.xinli.xinlifm.mvp.model.SuperModel;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

public class MoreActivity extends AppCompatActivity implements View.OnClickListener {

    private WebView moreView;
    private TextView titleText;
    private ImageView back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more);

        Intent intent = getIntent();
        String id = intent.getStringExtra("ids");
        String title = intent.getStringExtra("title");


        moreView = (WebView) findViewById(R.id.more_view);
        titleText = (TextView) findViewById(R.id.player_more_title);
        back = (ImageView) findViewById(R.id.player_more_back);
        Log.e("自定义标签", "类名==MoreActivity" + "方法名==onCreate=====:" + id);
        titleText.setText(title);
        back.setOnClickListener(this);
        getHttp(id);

    }

    @Override
    public void onClick(View v) {
        finish();
    }
    public void getHttp(String id){

        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder().get().url("http://bapi.xinli001.com/fm2/article.json/?pk="+id+"&key=046b6a2a43dc6ff6e770255f57328f89").build();
        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                final String string = response.body().string();
                Log.e("自定义标签", "类名==MoreActivity" + "方法名==onResponse=====:" + string);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            JSONObject jsonObject = new JSONObject(string);
                            String data = jsonObject.getString("data");
                            int code = jsonObject.getInt("code");
                            Log.e("自定义标签", "类名==MoreActivity" + "方法名==run=====:" + code+"--"+data);
//                            moreView.loadUrl(data);
                            moreView.loadData(data,"text/html;charset=utf-8",null);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        });

    }
}
